csv_file = "/data1/zyx/yks/dataset/retail/wangbo_stage2/ub/res_combine_kohill_networkx_kohill_iou.csv"
img_root = "/data1/zyx/yks/dataset/retail/test_stage2"
import numpy as np
import pprint,os
from PIL import Image
from data.bbox.bbox_dataset import DetectionDataset
from tqdm import tqdm
class DetDatset(DetectionDataset):
    def __init__(self):
        lines = open(csv_file,"rt").readlines()
        lines = np.array(map(lambda x:x.strip().split(','), lines))
        # name. x0, y0, x1, y1, score, id
        self.names = np.unique(lines[:,0])
        from random import shuffle
        shuffle(self.names)
        self.objs = {}
        for name in self.names:
            self.objs[name] = lines[np.where(lines[:,0] == name)][:,1:6]
        self.classes = ["person"]
    def at_with_image_path(self, idx):
        name = self.names[idx]
        obj = self.objs[name]
        obj[:,4] = 0
        obj = obj.astype(np.float)
        obj = obj.astype(np.int32)
        return os.path.join(img_root,name),obj

    def __len__(self):
        return len(self.names)
DetDatset().to_pascal(dir="/data1/zyx/yks/dataset/retail/test_stage2_voc")
# from utils.common import lsdir
# class Pascal(DetectionDataset):
#     def __init__(self):
#         all_xmls = lsdir("/data1/zyx/yks/dataset/retail/test_a_pascal", suffix=".xml")
#         self.objs = [self.parser_pascal_voc_xml(x,img_root) for x in all_xmls]
#         self.classes = ["person"]
#     def __len__(self):
#         return len(self.objs)
#     def at_with_image_path(self, idx):
#         obj = self.objs[idx]
#         bboxes = obj["bndbox"]
#         bboxes = np.array(bboxes)
#         bboxes[:,4] = map(lambda x:self.classes.index(x), bboxes[:,4])
#         path = obj["path"]
#         return path, bboxes.astype('f')
# Pascal().viz()